/*
 * Common.hpp
 *
 *  Created on: Aug 3, 2009
 *      Author: naveenoid
 */

#ifndef COMMON_HPP_
#define COMMON_HPP_


namespace Octopus
{
namespace Common
{

#define PRINT_MODE 1 //1 - Console, 2 - File, 3 - Silent

#define TEST_SETUP 2 // 1 - Single Motor and Sensor, 2 - 4 Motors and 4 Sensors, 3 - 13 Motors and 16 Sensors

#define CONTROLLER_TYPE 3 // 1 - FeedForward P, 2 - FeedForward PD, 3 - FeedForward PI

#define LOOP_TYPE 2 // 1 - Calibration only, 2 -Calibration and Control

#define TRAJECTORY_TYPE 1 // 1 - Horizontal Wave-like, Vertical Wave-like, Unrolling
//Trajectory
#if (TRAJECTORY_TYPE == 1) || (TRAJECTORY_TYPE == 2)
#define WAIT_TIME 5.0
#define WAVE_AMPLITUDE 2.5 //Peak to Peak
#define WAVE_FREQUENCY 0.75
#endif


//Motor Limits
#define MOTOR_POS_MIN 1100 // Motor min position
#define MOTOR_POS_MAX 1900 // Motor min position

#if TEST_SETUP == 1
	#define MAX_NUM_OF_MOTOR 1 // Test Setup
	#define MAX_NUM_OF_SENSOR 1 //Size of ADC vector
#elif TEST_SETUP == 2
	#define MAX_NUM_OF_MOTOR 4 // Test Setup
	#define MAX_NUM_OF_SENSOR 4 //Size of ADC vector
#else
	#define MAX_NUM_OF_MOTOR 13 // Test Setup
	#define MAX_NUM_OF_SENSOR 16 //Size of ADC vector
#endif


#if TEST_SETUP == 2
#define MOTOR1 true //forward
#define MOTOR2 false //reversed
#define MOTOR3 true //forward
#define MOTOR4 false //reversed

const bool motorState[4] = { MOTOR1, MOTOR2, MOTOR3, MOTOR4};
#else
const bool motorState[MAX_NUM_MOTOR];
#endif

//Board Stuff
#define READ_TIMEOUT 500
#define WRITE_TIMEOUT 500

//ADC and Pot Ranges
#define POT_MAX_DISTANCE 0.045 // unit m
#define POT_SPRING_STIFFNESS 685.8 //76.98 //685.8 //unit N/m
#define ADC_MAX_RANGE 1023 // Max ADC
#define ADC_MAX_NUM_CHANNELS 16

//Setup
#define LOAD_SPRING_STIFFNESS 200.0 //unit N/m
#define WHEEL_DIAMETER 0.35 //unit m

//Control Loop
#define LOOP_TIME 50000 //uSec

#if CONTROLLER_TYPE == 1
	#define K_P 30 //unit deg/N
	#define K_D 0
	#define K_I 0
#elif CONTROLLER_TYPE == 2
	#define K_P 10 //unit deg/N
	#define K_D 0.5  // unit deg/N
	#define K_I 0
#elif CONTROLLER_TYPE == 3
	#define K_P 20 //20 //unit deg/N
	#define K_D 3.5  // unit deg/N
	#define K_I 7.0 //8.0
#endif

#define TENSION_SAFETY_LIMIT 12 //N

#define PI 3.14159265 //pi!


void sWait(double);
void uWait(long int);


}
}


#endif /* COMMON_HPP_ */
